// $ANTLR 3.4 /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/evaluator/MathEvaluator.g 2011-09-15 11:09:01

  package id.co.rho.framework.math.evaluator;
  import java.math.BigDecimal;

import id.co.rho.scoring.cid.framework.math.evaluator.model.*;


import org.antlr.runtime.*;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class MathEvaluatorParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "CHAR", "COMMENT", "ESC_SEQ", "EXPONENT", "FLOAT", "HEX_DIGIT", "ID", "INT", "OCTAL_ESC", "UNICODE_ESC", "WS", "'('", "')'", "'*'", "'+'", "'-'", "'/'", "'mod'"
    };

    public static final int EOF=-1;
    public static final int T__15=15;
    public static final int T__16=16;
    public static final int T__17=17;
    public static final int T__18=18;
    public static final int T__19=19;
    public static final int T__20=20;
    public static final int T__21=21;
    public static final int CHAR=4;
    public static final int COMMENT=5;
    public static final int ESC_SEQ=6;
    public static final int EXPONENT=7;
    public static final int FLOAT=8;
    public static final int HEX_DIGIT=9;
    public static final int ID=10;
    public static final int INT=11;
    public static final int OCTAL_ESC=12;
    public static final int UNICODE_ESC=13;
    public static final int WS=14;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public MathEvaluatorParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public MathEvaluatorParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return MathEvaluatorParser.tokenNames; }
    public String getGrammarFileName() { return "/Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g"; }



    // $ANTLR start "id.co.rho.framework.math.evaluator"
    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:21:1: id.co.rho.framework.math.evaluator returns [MEValueNode res] : expression EOF ;
    public final MEValueNode evaluator() throws RecognitionException {
        MEValueNode res = null;


        MEValueNode expression1 =null;


        try {
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:22:3: ( expression EOF )
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:22:5: expression EOF
            {
            pushFollow(FOLLOW_expression_in_evaluator47);
            expression1=expression();

            state._fsp--;


            match(input,EOF,FOLLOW_EOF_in_evaluator49); 

            res = expression1;

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "id.co.rho.framework.math.evaluator"



    // $ANTLR start "term"
    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:24:1: term returns [MEValueNode res] : ( ID | '(' expression ')' | FLOAT | INT );
    public final MEValueNode term() throws RecognitionException {
        MEValueNode res = null;


        Token ID2=null;
        Token FLOAT4=null;
        Token INT5=null;
        MEValueNode expression3 =null;


        try {
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:25:2: ( ID | '(' expression ')' | FLOAT | INT )
            int alt1=4;
            switch ( input.LA(1) ) {
            case ID:
                {
                alt1=1;
                }
                break;
            case 15:
                {
                alt1=2;
                }
                break;
            case FLOAT:
                {
                alt1=3;
                }
                break;
            case INT:
                {
                alt1=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;

            }

            switch (alt1) {
                case 1 :
                    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:26:2: ID
                    {
                    ID2=(Token)match(input,ID,FOLLOW_ID_in_term68); 

                    res = new LeafValueNode((ID2!=null?ID2.getText():null));

                    }
                    break;
                case 2 :
                    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:27:4: '(' expression ')'
                    {
                    match(input,15,FOLLOW_15_in_term76); 

                    pushFollow(FOLLOW_expression_in_term78);
                    expression3=expression();

                    state._fsp--;


                    match(input,16,FOLLOW_16_in_term80); 

                    res = expression3;

                    }
                    break;
                case 3 :
                    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:28:4: FLOAT
                    {
                    FLOAT4=(Token)match(input,FLOAT,FOLLOW_FLOAT_in_term87); 

                    res = new LeafValueNode(new BigDecimal((FLOAT4!=null?FLOAT4.getText():null)));

                    }
                    break;
                case 4 :
                    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:29:4: INT
                    {
                    INT5=(Token)match(input,INT,FOLLOW_INT_in_term95); 

                    res = new LeafValueNode(new BigDecimal((INT5!=null?INT5.getText():null)));

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "term"



    // $ANTLR start "unary"
    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:32:1: unary returns [MEValueNode res] : ( '+' | '-' )* term ;
    public final MEValueNode unary() throws RecognitionException {
        MEValueNode res = null;


        MEValueNode term6 =null;


        try {
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:32:34: ( ( '+' | '-' )* term )
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:33:2: ( '+' | '-' )* term
            {
            boolean positive = true;

            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:34:4: ( '+' | '-' )*
            loop2:
            do {
                int alt2=3;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==18) ) {
                    alt2=1;
                }
                else if ( (LA2_0==19) ) {
                    alt2=2;
                }


                switch (alt2) {
            	case 1 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:34:5: '+'
            	    {
            	    match(input,18,FOLLOW_18_in_unary123); 

            	    }
            	    break;
            	case 2 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:34:11: '-'
            	    {
            	    match(input,19,FOLLOW_19_in_unary127); 

            	    positive=false;

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            pushFollow(FOLLOW_term_in_unary133);
            term6=term();

            state._fsp--;



              		res = term6;
              		if(!positive) {
              			res = new UnaryOpValueNode(res,Operator.UNARY_MIN);
              		}
              		

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "unary"



    // $ANTLR start "mult"
    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:42:1: mult returns [MEValueNode res] : o1= unary ( '*' o2= unary | '/' o3= unary | 'mod' o4= unary )* ;
    public final MEValueNode mult() throws RecognitionException {
        MEValueNode res = null;


        MEValueNode o1 =null;

        MEValueNode o2 =null;

        MEValueNode o3 =null;

        MEValueNode o4 =null;


        try {
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:42:32: (o1= unary ( '*' o2= unary | '/' o3= unary | 'mod' o4= unary )* )
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:43:3: o1= unary ( '*' o2= unary | '/' o3= unary | 'mod' o4= unary )*
            {
            pushFollow(FOLLOW_unary_in_mult155);
            o1=unary();

            state._fsp--;


            res = o1;

            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:44:3: ( '*' o2= unary | '/' o3= unary | 'mod' o4= unary )*
            loop3:
            do {
                int alt3=4;
                switch ( input.LA(1) ) {
                case 17:
                    {
                    alt3=1;
                    }
                    break;
                case 20:
                    {
                    alt3=2;
                    }
                    break;
                case 21:
                    {
                    alt3=3;
                    }
                    break;

                }

                switch (alt3) {
            	case 1 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:45:5: '*' o2= unary
            	    {
            	    match(input,17,FOLLOW_17_in_mult167); 

            	    pushFollow(FOLLOW_unary_in_mult171);
            	    o2=unary();

            	    state._fsp--;


            	    res = new BinaryOpValueNode(res, o2, Operator.MULT);

            	    }
            	    break;
            	case 2 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:46:7: '/' o3= unary
            	    {
            	    match(input,20,FOLLOW_20_in_mult181); 

            	    pushFollow(FOLLOW_unary_in_mult185);
            	    o3=unary();

            	    state._fsp--;


            	    res = new BinaryOpValueNode(res, o3, Operator.DIV);

            	    }
            	    break;
            	case 3 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:47:7: 'mod' o4= unary
            	    {
            	    match(input,21,FOLLOW_21_in_mult195); 

            	    pushFollow(FOLLOW_unary_in_mult199);
            	    o4=unary();

            	    state._fsp--;


            	    res = new BinaryOpValueNode(res, o4, Operator.MOD);

            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "mult"



    // $ANTLR start "expression"
    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:51:1: expression returns [MEValueNode res] : o1= mult ( '+' o2= mult | '-' o3= mult )* ;
    public final MEValueNode expression() throws RecognitionException {
        MEValueNode res = null;


        MEValueNode o1 =null;

        MEValueNode o2 =null;

        MEValueNode o3 =null;


        try {
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:51:38: (o1= mult ( '+' o2= mult | '-' o3= mult )* )
            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:52:3: o1= mult ( '+' o2= mult | '-' o3= mult )*
            {
            pushFollow(FOLLOW_mult_in_expression226);
            o1=mult();

            state._fsp--;


            res = o1;

            // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:53:3: ( '+' o2= mult | '-' o3= mult )*
            loop4:
            do {
                int alt4=3;
                int LA4_0 = input.LA(1);

                if ( (LA4_0==18) ) {
                    alt4=1;
                }
                else if ( (LA4_0==19) ) {
                    alt4=2;
                }


                switch (alt4) {
            	case 1 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:54:5: '+' o2= mult
            	    {
            	    match(input,18,FOLLOW_18_in_expression238); 

            	    pushFollow(FOLLOW_mult_in_expression242);
            	    o2=mult();

            	    state._fsp--;


            	    res = new BinaryOpValueNode(res, o2, Operator.ADD);

            	    }
            	    break;
            	case 2 :
            	    // /Users/bungrudi/Documents/Workspace/PEFINDO/pefindocid/src/main/java/id/co/rho/framework/math/id.co.rho.framework.math.evaluator/MathEvaluator.g:55:7: '-' o3= mult
            	    {
            	    match(input,19,FOLLOW_19_in_expression252); 

            	    pushFollow(FOLLOW_mult_in_expression255);
            	    o3=mult();

            	    state._fsp--;


            	    res = new BinaryOpValueNode(res, o3, Operator.SUB);

            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "expression"

    // Delegated rules


 

    public static final BitSet FOLLOW_expression_in_evaluator47 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_evaluator49 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_term68 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_15_in_term76 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_expression_in_term78 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_16_in_term80 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_FLOAT_in_term87 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INT_in_term95 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_18_in_unary123 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_19_in_unary127 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_term_in_unary133 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_unary_in_mult155 = new BitSet(new long[]{0x0000000000320002L});
    public static final BitSet FOLLOW_17_in_mult167 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_unary_in_mult171 = new BitSet(new long[]{0x0000000000320002L});
    public static final BitSet FOLLOW_20_in_mult181 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_unary_in_mult185 = new BitSet(new long[]{0x0000000000320002L});
    public static final BitSet FOLLOW_21_in_mult195 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_unary_in_mult199 = new BitSet(new long[]{0x0000000000320002L});
    public static final BitSet FOLLOW_mult_in_expression226 = new BitSet(new long[]{0x00000000000C0002L});
    public static final BitSet FOLLOW_18_in_expression238 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_mult_in_expression242 = new BitSet(new long[]{0x00000000000C0002L});
    public static final BitSet FOLLOW_19_in_expression252 = new BitSet(new long[]{0x00000000000C8D00L});
    public static final BitSet FOLLOW_mult_in_expression255 = new BitSet(new long[]{0x00000000000C0002L});

}